package com.yuanqiao.insight.modules.grok.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanqiao.insight.common.util.common.RedisUtils;
import com.yuanqiao.insight.modules.grok.entity.UtlGrokFormula;
import com.yuanqiao.insight.modules.grok.mapper.UtlGrokFormulaMapper;
import com.yuanqiao.insight.modules.grok.service.IUtlGrokFormulaService;
import com.insight.common.constant.CacheConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: gork表达式
 * @Author: jeecg-boot
 * @Date: 2024-02-19
 * @Version: V1.0
 */
@Service
public class UtlGrokFormulaServiceImpl extends ServiceImpl<UtlGrokFormulaMapper, UtlGrokFormula> implements IUtlGrokFormulaService {

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public void add(UtlGrokFormula utlGrokFormula) {
        final int i = super.baseMapper.insert(utlGrokFormula);
        if (i > 0) {
            redisUtils.hset(CacheConstant.SYS_GROK_CACHE + ":" + utlGrokFormula.getGrokCode(), utlGrokFormula.getId(), utlGrokFormula.getGrokFormula());
        }
    }

    @Override
    public void modify(UtlGrokFormula utlGrokFormula) {
        final int i = super.baseMapper.updateById(utlGrokFormula);
        if (i > 0) {
            redisUtils.hset(CacheConstant.SYS_GROK_CACHE + ":" + utlGrokFormula.getGrokCode(), utlGrokFormula.getId(), utlGrokFormula.getGrokFormula());
        }
    }

    @Override
    public void delete(String id) {
        final UtlGrokFormula utlGrokFormula = this.getById(id);
        final int i = super.baseMapper.deleteById(id);
        if (i > 0) {
            redisUtils.hdel(CacheConstant.SYS_GROK_CACHE + ":" + utlGrokFormula.getGrokCode(), utlGrokFormula.getId());
        }
    }
}
